using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;

namespace Hearthbuddy.Windows
{
	/// <summary>
	/// Interaction logic for UpdateWindow.xaml
	/// </summary>
	/// <summary>
	/// UpdateWindow
	/// </summary>
	public partial class UpdateWindow : Window, IComponentConnector
	{
		private readonly string string_0;

		private readonly System.Timers.Timer timer_0 = new System.Timers.Timer(1000.0);

		private int int_0 = 60;
		/*
		internal RichTextBox richTextBox_0;

		internal Button button_0;

		internal Button button_1;*/

		private bool bool_0;

		public UpdateWindow(string filter)
		{
			string_0 = filter;
			InitializeComponent();
		}

		private void button_0_Click(object sender, RoutedEventArgs e)
		{
			timer_0.Stop();
			base.DialogResult = true;
			Close();
		}

		private void button_1_Click(object sender, RoutedEventArgs e)
		{
			base.DialogResult = false;
			Close();
		}

		private void method_0(object sender, RoutedEventArgs e)
		{
			string text = new WebClient().DownloadString("http://updates.buddyauth.com/GetNewestChangelog?filter=" + string_0);
			richTextBox_0.Document.Blocks.Add(new Paragraph(new Run(text)));
			timer_0.Elapsed += timer_0_Elapsed;
			timer_0.AutoReset = true;
			timer_0.Start();
		}

		private void timer_0_Elapsed(object sender, EventArgs e)
		{
			if (base.Dispatcher.Thread != Thread.CurrentThread)
			{
				base.Dispatcher.BeginInvoke(new EventHandler(timer_0_Elapsed), sender, e);
			}
			else if (int_0 == 0)
			{
				timer_0.Stop();
				button_1_Click(null, null);
			}
			else
			{
				button_1.Content = $"No ({int_0--})";
			}
		}

		private void method_1(object sender, MouseEventArgs e)
		{
			timer_0.Stop();
			button_1.Content = "No";
		}
		/*
		/// <summary>
		/// InitializeComponent
		/// </summary>
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (!bool_0)
			{
				bool_0 = true;
				Uri resourceLocator = new Uri("/Hearthbuddy;component/windows/updatewindow.xaml", UriKind.Relative);
				Application.LoadComponent(this, resourceLocator);
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[DebuggerNonUserCode]
		void IComponentConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
			default:
				bool_0 = true;
				break;
			case 1:
				((UpdateWindow)target).Loaded += GetAwaiter;
				((UpdateWindow)target).MouseMove += method_1;
				break;
			case 2:
				richTextBox_0 = (RichTextBox)target;
				break;
			case 3:
				button_0 = (Button)target;
				button_0.Click += button_0_Click;
				break;
			case 4:
				button_1 = (Button)target;
				button_1.Click += button_1_Click;
				break;
			}
		}*/
	}
}
